<%@ include file="css/header.jsp" %>
<title>Resend file</title>
<%
String userId;
String tcdTracking;
if((String)session.getAttribute("userId")==null||((String)session.getAttribute("userId")).trim().length() == 0) userId = "null";
else userId = (String)session.getAttribute("userId");
if((String)session.getAttribute("tcdTracking")==null||((String)session.getAttribute("tcdTracking")).trim().length() == 0) tcdTracking = "null";
else tcdTracking = (String)session.getAttribute("tcdTracking");
	if(!(userId.equals("null"))){
		if(tcdTracking.equals("1")){
%>
<script type="text/javascript">

	var jqueryOption = {};
	jqueryOption.grdRowNum = 50;
	jqueryOption.grdRowList = [50, 100, 200];
	jqueryOption.grdJsonReader = {
	    root: "rows",
	    page: "page",
	    total: "total",
	    records: "records",
	    repeatitems: true, //if 'false' will chage json reader format to 'name' require
	    //cell: "cell",
	    id: "0" //id: "id"
	};

$(document).ready(function() {
	$('#mnu li').hover(
	        function () {
	            //show its submenu
	            $('ul', this).slideDown(100);
	 
	        }, 
	        function () {
	            //hide its submenu
	            $('ul', this).slideUp(100);         
	        }
	    );
	
    	$("#btnSearch").click(function(){
    		TrackViewer.bindgrdTransaction(1);
            return false;
        });
	var converId = "<%= request.getAttribute("converId")%>";
	var typeShort = "<%= request.getAttribute("typeShort") %>";
        $("#grdTraffic").jqGrid({ 
        	url:'<%=request.getContextPath()%>/ResendFileServlet/Resend?converId='+converId+'&type='+typeShort,
        	datatype: 'json',
            mtype: 'POST',
            colNames:['ResourceFile','File','Date','Size','Times','Resend',],
            colModel:[
				{name:'resourcefile', index:'resourcefile',width:60, sortable:false,hidden:true},
				{name:'file', index:'file',width:50, sortable:false},
				{name:'date', index:'date',align:'center',width:20, sortable:false},
				{name:'size', index:'size',align:'center',width:10, sortable:false},
				{name:'times', index:'times',align:'center',width:10, sortable:false},
                {name:'resend', index:'resend',align:'center',title:false, width:10,sortable:true}
                
               ],
            postData: {
            },
            rowNum: jqueryOption.grdRowNum, //50
            rowList: jqueryOption.grdRowList, //[50, 100, 200]
            autowidth: true, //Equal Container !Not change when resize window
            height: -1, //Auto height
            scrollOffset: 1, //Hide scroll bar
            pager: '#pagerTraffic',
            rownumbers: true,
            viewrecords: true,
            sortname: 'time',
            sortorder: "desc",
            cache: false,
            caption: '<%=request.getAttribute("type")%>',
            emptyrecords: 'No result',
            jsonReader : jqueryOption.grdJsonReader,
            onPaging: function(pgButton){ //pgButton : check which button click
            	//bindGrdTraffic($("#grdTraffic").getGridParam('page'));
            },
            onSortCol: function(index, iCol, sortorder){
            	//bindGrdTraffic($("#grdTraffic").getGridParam('page'));
            },
            loadError: function(xhr, status, error) {
                
            },
            loadComplete: function(data) {
                //if (data.error) {alert(data.error);}
            	 var gridObj = $("#grdTraffic");
                 var ids = gridObj.jqGrid('getDataIDs');
                 var contentValue;
                 for (var i = 0; i < ids.length; i++) {
                     var rowid = ids[i];
                     var myCellData = gridObj.jqGrid('getDataIDs');
                     var resend = '<a href="javascript:void(0)" onClick="resend(\''+myCellData[i]+ '\'); return false">Resend</a>';
                     gridObj.jqGrid('setRowData',rowid,{resend:resend});
                     
                 }
            }
        });

        function bindGrdTraffic(ipage){
            $("#grdTraffic").jqGrid('setGridParam'
                    ,{url:"<%=request.getContextPath()%>/TrafficViewerServlet"
                        ,page: ipage}).trigger("reloadGrid");
        }


        
    });

function resend(file){
	var type = $("#type").val();
	var msg = "";
	var converId = $("#converid").val();
	if(type=="reJPMCTCD") msg = "confirm to resend file to JPMC";
	else if(type == "reTCDTCD") msg = "Confirm to resend file to TCD";
	else if(type == "reJPMCRD") msg = "Confirm to resend file to JPMC";
	else if(type == "reRDRD") msg = "Confirm to resend file to RD";
	$.msgbox(msg, {
        type : 'confirm',
        buttons : [
            {type: 'submit', value:'Yes'},
            {type: 'cancel', value:'No'}
        ]
    }, function(buttonPressed) {
        if(buttonPressed == 'Yes'){
			
        	$.ajax({
                type: 'POST',
                url: '<%=request.getContextPath()%>/ReDo/ReTCD?type='+type+'&fileName='+file+'&converId='+converId,
                dataType: 'json',
                beforeSend: showLoading(),
                success: function(data){
	                $.each(data, function(key, value) {
	                    if (key == 'error') {
	                        $.msgbox(value , {
	                            type : 'error'
	                        }, function(buttonPressed) {
	                            // your code here
	                        });
	                    } else { //No Error
	                    	$.msgbox('Send file success', {
	                            type : 'info'
	                        }, function(buttonPressed) {
	                        	if(type=="reJPMCTCD" || type == "reTCDTCD"){
	                       			window.location.href = "ViewServlet";
	                        	}else if(type=="reJPMCRD" || type == "reRDRD"){
	                        		window.location.href = "ViewServletRD";
	                        	}
	                        });
	                    }
	                    return false; //break each loop
	                });

	                hideLoading();
            	},
                error: function(){
                    $.msgbox('Cannot send file', {
                        type : 'error'
                    }, function(buttonPressed) {
                    	hideLoading();
                    });
                    
                }
            });
        }
    });

}
</script>

<body>
<div id="jp-main">
        <div class="jp-sheet">
            <div class="jp-sheet-tl"></div>
            <div class="jp-sheet-tr"></div>
            <div class="jp-sheet-bl"></div>
            <div class="jp-sheet-br"></div>
            <div class="jp-sheet-tc"></div>
            <div class="jp-sheet-bc"></div>
            <div class="jp-sheet-cl"></div>
            <div class="jp-sheet-cr"></div>
            <div class="jp-sheet-cc"></div>
            <div class="jp-sheet-body">
                <div class="jp-header">
                    <div class="jp-header-center">
                        <div class="jp-header-png"></div>
                        <div class="jp-header-jpeg"></div>
                    </div>
                        <div class="jp-header-fluid-object"></div>
                </div>
                <div class="jp-nav">
                	<div class="l"></div>
                	<div class="r"></div>
                	<ul class="jp-menu">
                		
                			<%if (session.getAttribute("tcdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServlet" ><span class="l"></span><span class="r"></span><span class="t">TCD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServletRD"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("tcdBilling").equals("1")){%>
					    	  <li>
					    	  	<a href="TCDBillingServlet"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">TCD Billing</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdBilling").equals("1")){%>
					    	  <li>
					    	  	<a href="RDBilling"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Billing</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (!(userId.equals("0"))){%>
					    	  <li>
					    	  	<a href="EditProfile.jsp"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">Edit profile</span></a>                		
                			  </li>
					      	<%} %>
                			
           		  		<li>
                			<a href="#"><span class="l"></span><span class="r"></span><span class="t">User Management</span></a>
							<ul>
								<%if (session.getAttribute("manageUsers").equals("1")){%>
						    		<li><a href="ManageAdminServlet">Manage users</a></li>
						      	<%} %>
						      	<%if (session.getAttribute("manageGroups").equals("1")){%>
					    			<li><a href="ManageGroupServlet">Manage groups</a></li>
					      		<%} %>
					      		<%if (session.getAttribute("userLog").equals("1")){%>
					    			<li><a href="UserLogServlet">User log</a></li>
					      		<%} %>
           					</ul>
               		  	</li>		
           		  	  	<li>
                			<a href="Logout"><span class="l"></span><span class="r"></span><span class="t">Logout</span></a>                		
                	  	</li>
               	  </ul>
                </div>
                <div class="jp-content-layout">
                  <div class="jp-post-body">
                     <h2 class="jp-postheader">Tracking</h2>
                      <div class="jp-postcontent">
                      <div id="ResendFile">
                       <fieldset id="fsSearchServiceList">
				        <legend class="pageTitleForm"><h3>Conversation ID : <%=request.getAttribute("converId")%></h3></legend>
				        <div>&nbsp;</div>
				        <label style="color: white;">Type : <%=request.getAttribute("type")%></label>
				   		<input type = "hidden" id = "type" value = "<%=request.getAttribute("typeShort")%>" ></input>     
				   		<input type = "hidden" id = "converid" value = "<%=request.getAttribute("converId")%>" ></input>     
				        <div>&nbsp;</div>
	                        <div id="content-placeholder">
	                         	<div id="jqgrid">
	                                <table id="grdTraffic"></table>
	                                <div id="pagerTraffic"></div>
	                            </div>
	                         </div>
				        </fieldset>               
			        	</div>
                      </div>
                  </div>
                </div>
            </div>
        </div>
</div>
    
</body>	
<%
		}else{
%>
<script type="text/javascript">
    	window.location.href = "EditProfile";
</script>
<%
		}
	}else{
%>
<script type="text/javascript">
	window.location.href = "LoginServlet";
</script>
<%
	}
	
%>
</html>